import request from '@/utils/request'

export function Save(url, data) {
    return request({
        url: url,
        method: 'post',
        data
    })
}

export function Post(url, data) {
    return request({
        url: url,
        method: 'post',
        data
    })
}

export function GetQuery(url, query) {
    // if (query) {
    //     query.time = new Date().getTime()
    // }
    return request({
        url: url,
        method: 'get',
        params: query
    })
}

export function GetUrl(url, query) {
    if (url) {
    // query.time = new Date().getTime()
        url = url + '?time=' + new Date().getTime()
    }
    return request({
        url: url,
        method: 'get',
        params: {}
    })
}

export function GetUrlArray(url, query) {
    if (url) {
    // query.time = new Date().getTime()
        url = url + '?time=' + new Date().getTime()
    }
    return request({
        url: url,
        method: 'get',
        responseType: 'blob'
    })
}

export function DeleteUrl(url, data) {
    return request({
        url: url,
        method: 'delete',
        data
    })
}

export function GetJson(url, data) {
    return request({
        url: url,
        method: 'get',
        data
    })
}

export function Put(url, data) {
    return request({
        url: url,
        method: 'put',
        data
    })
}

export function Get(url, data) {
    if (data) {
        data.time = new Date().getTime()
    }
    return request({
        url: url,
        method: 'get',
        data
    })
}

export function PostJson(url, data) {
    return request({
        url: url,
        method: 'post',
        data
    })
}

export function PostMap(url, map) {
    return request({
        url: url,
        method: 'post',
        data: map,
        transformRequest: [function(data) {
            // Do whatever you want to transform the data
            let ret = ''
            for (const it in data) {
                ret += encodeURIComponent(it) + '=' + encodeURIComponent(data[it]) + '&'
            }
            return ret
        }],
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded'
        }
    })
}
